package com.ruoyi.bole.integral.mapper;

import java.util.List;
import com.ruoyi.bole.integral.domain.BoleIntegralApplication;
import com.ruoyi.bole.integral.vo.IntegrationRankVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 积分申请Mapper接口
 * 
 * @author ruoyi
 * @date 2025-03-23
 */
public interface BoleIntegralApplicationMapper 
{
    List<BoleIntegralApplication> selectBoleIntegralApplicationByIds(@Param("ids") List<Long> ids);
//    @Insert("INSERT INTO bole_integral_application " +
//            "(user_id, type, score, apply_date, description, status, season_id, integral_souce) " +
//            "VALUES " +
//            "(#{userId}, #{type}, #{score}, #{applyDate}, #{description}, #{status}, #{seasonId}, #{integralSouce})")
//    public int insertMarkIntegral(BoleIntegralApplication boleIntegralApplication);
@Insert("INSERT INTO bole_integral_application " +
        "(user_id AS userId, type AS type, score AS score, " +
        "apply_date AS applyDate, description AS description, " +
        "status AS status, season_id AS seasonId, integral_souce AS integralSouce) " +
        "VALUES " +
        "(#{userId}, #{type}, #{score}, #{applyDate}, #{description}, #{status}, #{seasonId}, #{integralSouce})")
public int insertMarkIntegral(BoleIntegralApplication boleIntegralApplication);

    //积分排行
    @Select("SELECT " +
            "su.user_id AS userId, " +               // 显式别名
            "su.user_name AS userName, " +           // 显式别名
            "su.nick_name AS nickName," +
            "su.avatar, " +           // 显式别名
            "COALESCE(SUM(bia.score), 0) AS totalScore " +  // 显式别名
            "FROM sys_user su " +
            "LEFT JOIN bole_integral_application bia ON su.user_id = bia.user_id where bia.status = 1 " +
            "and bia.season_id=#{seasonId} " +
            "GROUP BY su.user_id, su.user_name, su.nick_name   " +  // 确保GROUP BY包含所有非聚合列
            "ORDER BY totalScore DESC " +            // 使用别名排序
            "LIMIT #{offset}, #{pageSize}")
    List<IntegrationRankVO> selectIntegrationRank(@Param("offset") int offset, @Param("pageSize") int pageSize,@Param("seasonId") Integer seasonId);
    /**
     * 查询积分申请
     * 
     * @param id 积分申请主键
     * @return 积分申请
     */
    public BoleIntegralApplication selectBoleIntegralApplicationById(Long id);

    /**
     * 查询积分申请列表
     * 
     * @param boleIntegralApplication 积分申请
     * @return 积分申请集合
     */
    public List<BoleIntegralApplication> selectBoleIntegralApplicationList(BoleIntegralApplication boleIntegralApplication);

    /**
     * 新增积分申请
     * 
     * @param boleIntegralApplication 积分申请
     * @return 结果
     */
    public int insertBoleIntegralApplication(BoleIntegralApplication boleIntegralApplication);

    /**
     * 修改积分申请
     * 
     * @param boleIntegralApplication 积分申请
     * @return 结果
     */
    public int updateBoleIntegralApplication(BoleIntegralApplication boleIntegralApplication);

    /**
     * 删除积分申请
     * 
     * @param id 积分申请主键
     * @return 结果
     */
    public int deleteBoleIntegralApplicationById(Long id);

    /**
     * 批量删除积分申请
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteBoleIntegralApplicationByIds(Long[] ids);
}
